#include "p_shared.h"
#include "..\pcommon\zone.h"


#define BUFLEN 4096
#define CMDLEN 20

pboolean g_cmd_with_gui = false;

pboolean Parse_Config(char* name)
{
	char	buf[BUFLEN];
	int		size;
	FILE* fp = fopen(name, "a+");

	if (NULL == fp)
	{
		fprintf(stderr, "Can't open file:\t%s.\n", name);
		return false;
	}
	
	while (!feof(fp) && !ferror(fp))
	{
		int i, j;
		char* cmds = NULL;

		size = fread(buf, sizeof(char), BUFLEN, fp);
		cmds = (char*)Z_Malloc(Get_Global_Zone(), size);
		memcpy(cmds, buf, size);
		cmds[size] = '\0';
		for (i = 0; i < size;)
		{
			char cmd[CMDLEN];
			j = 0;
			while ('\n' != cmds[j])
			{
				cmd[j] = cmds[i];
				++j;
				++i;
			}
			cmd[j] = '\0';
			if (0 == strcmp(cmd, "-with-gui"))
			{
				g_cmd_with_gui = true;
				break;
			}
			if (0 == strcmp(cmd, "-without-gui"))
			{
				g_cmd_with_gui = false;
				break;
			}
		}
	}

	fclose(fp);

	return true;
}